package example.chapter7;

import java.io.InputStream;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class PrintSourceAction extends ActionSupport{
	private InputStream inputStream;
	private String className;
	
	public String execute() throws Exception{
		if(className != null && className.trim().length() > 0){
//			className = "/" + className.replace('.', '/') + ".java";
			inputStream = ServletActionContext.getServletContext().getResourceAsStream(className);
			if(inputStream == null){
				inputStream = ServletActionContext.getServletContext().getResourceAsStream("/" + className);
			}
		}		
		return SUCCESS;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}
	
}
